package com.yej.aiPolice.presenter

import android.os.Looper
import android.util.Log
import com.baidu.ai.aip.bean.FaceAddBean
import com.baidu.ai.aip.faceAPI.FaceServiceImpl
import com.google.gson.Gson
import com.yej.aiPolice.model.beans.UserFaceInfoBean
import com.yej.aiPolice.ui.activity.AddFaceActivity
import org.jetbrains.anko.toast

class AddFaceActivityPresenter(val addFaceActivity: AddFaceActivity) {

    private var faceService = FaceServiceImpl()
    fun addFace( albumPath: String?,userFaceInfoBean: UserFaceInfoBean,userId:String){
//        var bitMap = IOUtil.readBitmapFromFileDescriptor(albumPath, 200, 200)
//        ivShow?.setImageBitmap(bitMap)
        Log.e("人脸",albumPath)
        var postThread = Thread(Runnable {

//            FaceAdd.add(albumPath, "testALL","ttt","ttt")
            var userInfoJson:String = Gson().toJson(userFaceInfoBean)
            Log.e("人脸",userInfoJson)
            var result = faceService.add(albumPath,"testGroup",userId,userInfoJson) as FaceAddBean
            Looper.prepare();
            if(result == null) {
                addFaceActivity.toast("代码有误")
//                context?.toast("代码错误")
                Log.e("人脸","代码有误")
            }else{
                Log.e("人脸",result.error_msg);
                addFaceActivity.onSearchSuccess()

            }
            Looper.loop();
        })
        postThread.start()
    }

    private fun parserJson(userInfo: String) {

    }
}